import sys
if __name__ == "__main__":
	try:
		skip = int(sys.argv[1])
	except:
		skip = 0
else:
	sys.exit(0)


import gzip, MySQLdb

conn = MySQLdb.connect(host="mysql.stalidis.com", user="ict4growth", passwd="stanford", db="ict4growth")
curs = conn.cursor()

#curs.execute('''CREATE TABLE Descriptions (ProductID text, Description text)''')
#curs.execute('SET autocommit = 0')
#conn.commit()

orfile = gzip.open("descriptions.txt.gz",'r')
buf = "start"
i = 0
while ((buf != '') and (i < 3*skip)):
	buf = orfile.readline()
	i += 1

pr_id = orfile.readline()
while pr_id != '':
	descr = orfile.readline()
	emt_l = orfile.readline()
	curs.execute("INSERT INTO Descriptions VALUES (%s,%s)",
		(":".join(pr_id.strip().split(":")[1:]).strip(),
		 ":".join(descr.strip().split(":")[1:]).strip()))
	pr_id = orfile.readline()

orfile.close()
conn.commit()
conn.close()



